// ----------------------------------
// RSDK Project: Sonic 2 - Boss Attack Plus
// Script Description: Attack Mode
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : 2PShift
private alias object.value1 : object.timer
private alias object.value2 : arrow.frame

// menu selections


//private alias 0 : 

// object states


private alias 0 : SONIC_TAILS
private alias 1 : SONIC
private alias 2 : TAILS
private alias 3 : KNUCKLES
private alias 4 : KNUCKLES_TAILS
private alias 5 : INACTIVE

private alias saveRAM[494] : saved.bossGameMode //7B8 SData.bin
private alias saveRAM[495] : saved.bossType //7BC SData.bin
private alias saveRAM[496] : saved.BossMusic //7C0 SData.bin
private alias saveRAM[497] : saved.Character //7C4 SData.bin
private alias saveRAM[498] : saved.TimeLimit //7C8 SData.bin
private alias saveRAM[499] : saved.superMode //7CC SData.bin

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//




//-------Functions-------//

function drawSonic
	LoadAnimation("Sonic.ani")
end function

function drawSSonic
	LoadAnimation("SuperSonic.ani")
end function

function drawTails
	LoadAnimation("Tails.ani")
end function

function drawKnuckles
	LoadAnimation("Knuckles.ani")
end function



event ObjectMain
	if object.state != INACTIVE
		if inputPress.down == 1
			if saved.Character < 4
				saved.Character ++
				object.frame = 0
			else
				saved.Character = 0
				object.frame = 0
			endif
		playSFX(SFXName[Menu Move], 0)
		endif
		if inputPress.up == 1
			if saved.Character > 0
				saved.Character --
				object.frame = 0
			else
				saved.Character = 4
				object.frame = 0
			endif
		playSFX(SFXName[Menu Move], 0)
		endif
	endif
	object.animation = ANI_WAITING
	temp0 = screen.xcenter
	temp0 += 2PShift
	object.ixpos = temp0
	if saved.Character == TAILS
		object.iypos = 96
	else
		object.iypos = 92
	endif

	if saved.Character == TAILS
		object[+1].visible = 1
	else
		object[+1].visible = 0
	endif

	switch saved.Character
	case SONIC_TAILS
		if saved.superMode == 0
			CallFunction(drawSonic)
		else
			CallFunction(drawSSonic)
		endif
		stage.playerListPos = 0
		stage.player2Enabled = 1

		object.animationSpeed ++
		if object.animationSpeed > 7
			object.frame ++
			if object.frame > 42
				object.frame = 6
			endif
			object.animationSpeed = 0
		endif
		2PShift = 12
		break
	case SONIC
		if saved.superMode == 0
			CallFunction(drawSonic)
		else
			CallFunction(drawSSonic)
		endif
		stage.playerListPos = 0
		stage.player2Enabled = 0

		object.animationSpeed ++
		if object.animationSpeed > 7
			object.frame ++
			if object.frame > 42
				object.frame = 6
			endif
			object.animationSpeed = 0
		endif
		2PShift = 0
		break
	case TAILS
		CallFunction(drawTails)
		stage.playerListPos = 1
		stage.player2Enabled = 0
		object.animationSpeed ++
		if object.animationSpeed > 7
			object.frame ++
			if object.frame > 48
				object.frame = 21
			endif
			object.animationSpeed = 0
		endif
		2PShift = 0
		break
	case KNUCKLES
		CallFunction(drawKnuckles)
		stage.playerListPos = 2
		stage.player2Enabled = 0

		object.animationSpeed ++
		if object.animationSpeed > 7
			object.frame ++
			if object.frame > 98
				object.frame = 0
			endif
			object.animationSpeed = 0
		endif
		2PShift = 0
		break
	case KNUCKLES_TAILS
		CallFunction(drawKnuckles)
		stage.playerListPos = 2
		stage.player2Enabled = 1

		object.animationSpeed ++
		if object.animationSpeed > 7
			object.frame ++
			if object.frame > 98
				object.frame = 0
			endif
			object.animationSpeed = 0
		endif
		2PShift = 12
		break
	endswitch
end event

event ObjectDraw
	DrawObjectAnimation()
	object.drawOrder = 4
	if object.state != INACTIVE
		if object.timer > 7
			object.timer = 0
			arrow.frame ^= 1
		else
			object.timer++
		endif
		DrawSpriteScreenXY(arrow.frame, screen.xcenter, 68)
		temp0 = arrow.frame
		temp0 += 2
		DrawSpriteScreenXY(temp0, screen.xcenter, 116)
	endif
end event

event ObjectStartup
	ReadSaveRAM()

	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(-4, -3, 9, 6, 87, 279)			//00 Arrow Up
	SpriteFrame(0, 0, 0, 0, 0, 0)				//01 Arrow Up Blank
	SpriteFrame(-4, -3, 9, 6, 87, 286)			//02 Arrow Down
	SpriteFrame(0, 0, 0, 0, 0, 0)				//03 Arrow Down Blank
end event

event RSDKDraw
    DrawSprite(0)
end event

event RSDKLoad
    LoadSpriteSheet("Global/Display.gif")
    SpriteFrame(-16, -16, 32, 32, 223, 172)
end event